import './App.css';
import { CopilotSidebar } from "@copilotkit/react-ui";
import "@copilotkit/react-ui/styles.css";
import { RouterProvider } from 'react-router-dom';
import router from './router';
import { Suspense } from 'react';
import copy from 'clipboard-copy';

const LoadingSpinner = () => <div>Loading...</div>;

export default function App() {

  const onSetOpen = (val) => {
    console.log('🚀 CopilotSidebar 已打开',val);
  };

  const onCopy = (val) => {
    console.log('🚀 CopilotSidebar 已复制',val);
    handleCopy(val)
  };

  const onThumbsUp = (val) => {
    console.log('🚀 onThumbsUp',val);
  };

  const onThumbsDown = (val) => {
    console.log('🚀 onThumbsDown',val);
  };

  const handleCopy = async (val) => {
  try {
    await copy(val);
    console.log('复制成功!');
  } catch (err) {
    console.error('复制失败:', err);
  }
};
  

  return (
    <CopilotSidebar
      labels={{
        title: "AI 助手",
        initial: "你好！我是你的AI助手，有什么我可以帮你的吗？",
        placeholder:"请输入你的问题...",
        stopGenerating:"停止生成",
        regenerateResponse:"重新生成",
        copyToClipboard:"复制",
        thumbsUp:"赞",
        thumbsDown:"踩",
        copied:"已复制",
      }}
      defaultOpen={false}
      onSetOpen={onSetOpen}
      onCopy={onCopy}
      onThumbsUp={onThumbsUp}
      onThumbsDown={onThumbsDown}
      // observabilityHooks={{
      //   onChatExpanded: handleChatExpanded,
      //   onChatMinimized: handleChatMinimized
      // }}
      // // 启用图像上传功能，支持Word、Excel等文档
      // imageUploadsEnabled={true}
      // // 设置接受的文件类型，包括Word、Excel和其他文档类型
      // inputFileAccept=".doc,.docx,.xls,.xlsx,.pdf,.txt,.csv,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/pdf,text/plain"
    >
      <Suspense fallback={<LoadingSpinner />}>
        <RouterProvider router={router} />
      </Suspense>
    </CopilotSidebar>
  );
}